﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms.DataVisualization.Charting;
using EmbeddedSharp.Core;
using System.Configuration;

namespace EmbeddedSharp.Scripting.Visualization
{
    public class PlotSharpSeries : Series
    {
        public PlotSharpSeries()
            : base()
        {
        }

        public PlotSharpSeries(string name)
            : base(name)
        {
        }

        public PlotSharpSeries(string name, int value)
            : base(name, value)
        {
        }

        public PlotSharpSeries(
            string name, IUnaryParameterFunction f, double from, double to)
            : base(name)
        {
            object prec = ConfigurationManager.AppSettings["plotprec"];
            double precision;
            if (prec == null)
            {
                precision = 100;
            }
            else
            {
                precision = Convert.ToDouble(prec);
            }

            double step = (to - from) / precision;
            for (double x = from; x < to; x = x + step)
            {
                double y = f.Eval(x);
                Points.AddXY(x, y);
            }
        }
    }
}
